Compiler

RSS for tag

Discuss the various compiler and toolchain technologies used in development.

Posts under Compiler tag

113 Posts
Sort by:
Post marked as solved
3 Replies
989 Views
Hi -- I am attempting to use C++ and Swift in a single project but I am struggling with finding the proper way to do this. Ideally I want to have both my C++ and Swift code in the same project and not use a framework to keep them separate. As an example, how would I create an object of the following C++ class: class Foo { public: Foo() { // do stuff } } From what I read, it should be as simple as this: let foo = Foo() But Xcode says it Cannot find 'Foo' in scope. How do I import Foo into my Swift code? Is there a project setting that needs to be changed to automatically make my C++ classes available? Or do I need to create a Clang module (as described in this page: https://www.swift.org/documentation/cxx-interop/#importing-c-into-swift) to expose the C++ code to Swift? If so, where in my Xcode project should that go? I am using Xcode 15.2 on macOS 14.2.1. I have also set the C++ and Objective-C Interoperability setting for my project to C++/Objective-C++.
Posted
by dpm.
Last updated
.
Post not yet marked as solved
1 Replies
134 Views
We are facing an issue on Catalyst when building our app using Xcode 15.4. The issue is related to precompiled frameworks and seems to be widespread as it happens with multiple vendors (like Firebase or Braze). We are using SPM to add these dependencies, for instance: .package(url: "https://github.com/braze-inc/braze-swift-sdk", from: "8.2.1"), When building, we get the following error: clang:1:1: invalid version number in '-target arm64-apple-ios10.15-macabi' Our macOS deployment target is 12.3. Our iOS deployment target is 15.4. I will try to create a reproducer I can share but I wanted to share this in case there's a known workaround. Thanks in advance!
Posted
by 0xpablo.
Last updated
.
Post not yet marked as solved
3 Replies
134 Views
I'm defining a typealias for a set, and then creating an extension for the new typealias. When I do this, I'm getting an odd syntax error. Any/all guidance appreciated. typealias IntSet = Set<Int> extension IntSet { func aFunction() -> Set<String> { let array: [String] = self.map { "\($0)" } return Set(array) } } At the return line, I get the following syntax error: Cannot convert return expression of type 'Set<Int>' to return type 'Set<String>' Even if I replace the return line with the following, I get the same compile error return Set("array")
Posted Last updated
.
Post not yet marked as solved
1 Replies
129 Views
For calling swift api of a class to cpp , we need to include SwiftInterfaceGeneratedHeader to cpp file and then we can access swift class api in cpp . Signature of swift class with public apis will be added to the SwiftInterfaceGeneratedHeader. We find an odd behaviour here . Signature of classes will be added to SwiftInterfaceGeneratedHeader in alphabetical order (swift class name alphabetically lower will be added first to generated header). If we have a swift class which is referenced by another swift class Api , then referenced class's name should be alphabetically lower that referee class , otherwise we will get a build error :- "Unknown class name". public class A { public func funca () { print ("class A") } } public class B { public func funcb () { print ("class B") } public func funcb2 (pA:A) { pA.funca() } public func funcb3 (pC:C) { pC.funcc() } } public class C { public func funcc () { print ("class C") } } Cpp class where we include bridging header after turning on swift cpp interop : class Test1 { public: static void testfunc (); }; #include "Test1.hpp" #include "cppswiftinterop-Swift.h" void Test1::testfunc() { } Here , we have three swift classes , Class A,B,C. And since we are including SwiftInterfaceGeneratedHeader in cpp , signature of these class will be added to the generated header . In this project , we are referencing Class A and Class C from Class B . And since A is alphabetically lower that B , it works fine (because signature of A in Generated header will be added before it is referenced by B). But since C is alphabetically above than B , it will through build error (Unknown type name 'C') , because Signature of C in Generated header will be added after it is referenced by class B). If i rename Class C to Class AA then , it works fine. Is this a bug in swift cpp interop?
Posted Last updated
.
Post not yet marked as solved
0 Replies
133 Views
Hi People :) I'm experimenting with Swift/C++ interoperability these days. I'd like to understand how could I conform a Swift class to Cxx header: Like this: import Application class App: Application { public func run() { let app = NSApplication.shared let delegate = AppDelegate() app.delegate = delegate app.run() } } But I got this error: /Users/tonygo/oss/native-research/App.swift:27:7: error: inheritance from non-protocol, non-class type 'Application' class App: Application { ^ ninja: build stopped: subcommand failed. That seems normal indeed. Reproductible example: https://github.com/tony-go/native-research/tree/conform-swift-to-cxx-header (Just run make) I also have another branch on that repo where I use an intermediate Cxx bridge file that conforms to the :Application class and use the Swift API, like this: https://github.com/tony-go/native-research/tree/main/app Bit I think that its a lot of boilerplate. So I wonder which approach could I take for this? Cheers :)
Posted
by tonygo.
Last updated
.
Post not yet marked as solved
0 Replies
107 Views
I'm seeing some weird behavior with conditional compilation when I use a build configuration other than "Debug" or "Release", and I'm wondering if I'm doing something wrong or if this is an Xcode bug. The setup Xcode version: 15.3 I have a simple SwiftUI view that takes in a model and displays an attribute of the model. struct ContentView: View { let model: Model var body: some View { VStack { Text("Name: \(model.name)") } .padding() } } In the model file, I have the struct definition, but also an extension that defines some sample data for use in SwiftUI previews: struct Model { let id: String let name: String } #if DEBUG extension Model { static let example = Model( id: "50fef362-f53d-4ded-9168-b887ff62e59d", name: "John Doe" ) } #endif And finally, I have a preview provider that uses this sample data: #Preview { ContentView(model: Model.example) } Normal behavior With the default "Debug" build configuration, this works just fine. There are no compilation errors, and the preview renders as expected. The issue Start off by changing the name of the build configuration to, e.g. "DebugDev" Now I start seeing seeing a mis-match between what happens and what Xcode tells me is happening. The code still compiles and runs, and the SwiftUI preview still works, but Xcode is displaying things as if it doesn't compile. Xcode formats the conditionally compiled code with a lower opacity color as if DEBUG isn't defined: In the view file, I now see a compilation error when referencing the conditionally-compiled code: Autocomplete doesn't work when trying to reference the conditionally compiled code Additional details/observations I have confirmed that the DEBUG active compilation condition is still defined in the build settings. All I've done is change the name of the build config I was initially thinking this might have something to do with the fact that this appears in a preview provider, since those are treated a bit differently, but the same thing happens if I reference the conditionally compiled code directly in the view class Another theory: since I was referencing conditionally compiled code from code that wasn't conditionally compiled, maybe Xcode was trying to tell me that wasn't valid. So, I tried placing the code that calls the conditionally compiled code (in this case, the view class) inside an #if DEBUG. This does get rid of the displayed compilation error, but auto-complete still doesn't work, and the whole class is displayed with the lower-opacity font. Help? I feel like I must be missing something. The only alternative I can think of is that Xcode has some logic hard-coded with the default "Debug" build config, and that would be...just silly.
Posted
by nivektric.
Last updated
.
Post not yet marked as solved
1 Replies
145 Views
Hello everyone! I'm currently working on an iOS app developed with Swift that involves connecting to a specific bluetooth device and exchanging data even when the app is terminated or running in the background. I just want to understand why the CBCenterManager should be Implicitly unwrapped to use it. I have check out couple off apple developer sample project it was set to Implicitly unwrapped. can some one help to understand the reason behind this, also what are possible issues/scenario trigger if we set the centermanager to optional "CBcentermanager?" Thanks in Advance!
Posted Last updated
.
Post not yet marked as solved
0 Replies
166 Views
Hi all, I'm attempting to generate an XCFramework that must maintain ABI stability. The framework is created from an SPM using the attached script generate-FK.sh. I does not work. Removing the flag BUILD_LIBRARY_FOR_DISTRIBUTION=YES and adding the flag -allow-internal-distribution to xcodebuild -create-xcframework everything is fine. Despite this resolves the problem, it results in the generated module not being ABI stable. However, when attempting the script approach, it generates the XCFramework but when used it raises an error in arm64-apple-ios-private.swiftinterface with no such file or module as soon as it encounters an import statement for ModuleX reading it. The package structure is attached as Package.swift and te obtained result XCFramework structure is as follows: MyLibrary.xcframework ├── Info.plist ├── ios-arm64 │ └── MyLibrary.framework │ ├── Headers │ │ ├── ModuleH-Swift.h │ │ ├── ModuleH.modulemap │ │ ├── ModuleC-Swift.h │ │ ├── ModuleC.modulemap │ │ ├── ModuleA-Swift.h │ │ ├── ModuleA.modulemap │ │ ├── MyLibrary-Swift.h │ │ └── MyLibrary.modulemap │ ├── Info.plist │ ├── Modules │ │ └── MyLibrary.swiftmodule │ │ ├── arm64-apple-ios.abi.json │ │ ├── arm64-apple-ios.swiftdoc │ │ └── arm64-apple-ios.swiftmodule │ └── MyLibrary └── ios-arm64_x86_64-simulator └── MyLibrary.framework ├── Headers │ ├── ModuleH-Swift.h │ ├── ModuleH.modulemap │ ├── ModuleC-Swift.h │ ├── ModuleC.modulemap │ ├── ModuleA-Swift.h │ ├── ModuleA.modulemap │ ├── MyLibrary-Swift.h │ └── MyLibrary.modulemap ├── Info.plist ├── Modules │ └── MyLibrary.swiftmodule │ ├── arm64-apple-ios-simulator.abi.json │ ├── arm64-apple-ios-simulator.swiftdoc │ ├── arm64-apple-ios-simulator.swiftmodule │ ├── x86_64-apple-ios-simulator.abi.json │ ├── x86_64-apple-ios-simulator.swiftdoc │ └── x86_64-apple-ios-simulator.swiftmodule ├── MyLibrary └── _CodeSignature └── CodeResources It's worth mentioning that the library must be compatible with both Objective-C and Swift, and Modules A, C, and H are imported into the MyLibrary module as @_exported modules, that is why I've included the headers and module maps. What is wrong? Thank you in advance for your assistance. Files: generate-FK.sh Package.swift
Posted Last updated
.
Post not yet marked as solved
2 Replies
194 Views
Hello, I'm working with Mac Book Pro M3 Sonoma 14.4.1 and I have an issue with compilation, sometimes after compilation of the project the symlink files inside Xcode.app are updated, and further compilation will do full recompilation. According to the build log, the issue is pthread.h : Module.NiagaraEditor.9.cpp: Dependency /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread.h is newer than the last execution of the action: 04/23/2024 14:33:55 vs 04/23/2024 00:20:32 I tried to trace the reason for the symlink update with the fs_usage utility like this: sudo fs_usage -w | grep pthread.h and according to the output the only things that coincide with the file modification time: 13:55:37.157163 lstat64 [ 2] -B918-ED122786C40E.activeSandbox/Root//Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread/pthread.h 0.000034 installd.1747894 13:55:37.159691 link ED122786C40E.activeSandbox/Root//Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/pthread/pthread.h 0.000753 installd.1747894 13:55:37.176355 fsgetpath -ED122786C40E.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/pthread/pthread.h 0.000039 mds.1764823 13:55:37.176612 fsgetpath activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/pthread/pthread.h 0.000026 mds.1764823 13:55:37.176641 fsgetpath 18-ED122786C40E.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/pthread/pthread.h 0.000016 mds.1764823 13:55:37.176666 fsgetpath E.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/pthread/pthread.h 0.000014 mds.1764823 13:55:37.176689 fsgetpath 8-B918-ED122786C40E.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread/pthread.h 0.000014 mds.1764823 13:55:37.186224 lstat64 [ 2] A13-4108-B918-ED122786C40E.activeSandbox/Root//Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread.h 0.000022 installd.1747894 13:55:37.186717 unlink [ 2] A13-4108-B918-ED122786C40E.activeSandbox/Root//Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread.h 0.000010 installd.1747894 There are link and unlink caused by installd process, which makes me think that it could be related to the system software update, but disabling it did not help.
Posted
by HyPNOTIQ.
Last updated
.
Post not yet marked as solved
0 Replies
153 Views
Hi all, I'm attempting to generate an XCFramework that must maintain ABI stability. The framework is created from an SPM using the attached script generate-FK.sh. I does not work. Removing the flag BUILD_LIBRARY_FOR_DISTRIBUTION=YES and adding the flag -allow-internal-distribution to xcodebuild -create-xcframework everything is fine. Despite this resolves the problem, it results in the generated module not being ABI stable. However, when attempting the script approach, it generates the XCFramework but when used it raises an error in arm64-apple-ios-private.swiftinterface with no such file or module as soon as it encounters an import statement for ModuleX reading it. The package structure is attached as Package.swift and te obtained result XCFramework structure is as follows: MyLibrary.xcframework ├── Info.plist ├── ios-arm64 │ └── MyLibrary.framework │ ├── Headers │ │ ├── ModuleH-Swift.h │ │ ├── ModuleH.modulemap │ │ ├── ModuleC-Swift.h │ │ ├── ModuleC.modulemap │ │ ├── ModuleA-Swift.h │ │ ├── ModuleA.modulemap │ │ ├── MyLibrary-Swift.h │ │ └── MyLibrary.modulemap │ ├── Info.plist │ ├── Modules │ │ └── MyLibrary.swiftmodule │ │ ├── arm64-apple-ios.abi.json │ │ ├── arm64-apple-ios.swiftdoc │ │ └── arm64-apple-ios.swiftmodule │ └── MyLibrary └── ios-arm64_x86_64-simulator └── MyLibrary.framework ├── Headers │ ├── ModuleH-Swift.h │ ├── ModuleH.modulemap │ ├── ModuleC-Swift.h │ ├── ModuleC.modulemap │ ├── ModuleA-Swift.h │ ├── ModuleA.modulemap │ ├── MyLibrary-Swift.h │ └── MyLibrary.modulemap ├── Info.plist ├── Modules │ └── MyLibrary.swiftmodule │ ├── arm64-apple-ios-simulator.abi.json │ ├── arm64-apple-ios-simulator.swiftdoc │ ├── arm64-apple-ios-simulator.swiftmodule │ ├── x86_64-apple-ios-simulator.abi.json │ ├── x86_64-apple-ios-simulator.swiftdoc │ └── x86_64-apple-ios-simulator.swiftmodule ├── MyLibrary └── _CodeSignature └── CodeResources It's worth mentioning that the library must be compatible with both Objective-C and Swift, and Modules A, C, and H are imported into the MyLibrary module as @_exported modules, that is why I've included the headers and module maps. What is wrong? Thank you in advance for your assistance.
Posted Last updated
.
Post not yet marked as solved
1 Replies
246 Views
I have an app that uses Swift 4.2. I am going to update the Swift Compiler Language to Swift 5. But I have some confusion after my test. I was able to run async/await code when using Xcode 15 with the version set to Swift 4.2, and it was okay. But async/await code was developed in Swift5.5. Why it is okay? Is it related to the Xocde Swift version? And if I use Swift Compiler version 4.2 to run async/await code,what problems might there be ?
Posted
by jayzhuang.
Last updated
.
Post not yet marked as solved
1 Replies
331 Views
After updating our build server to Xcode 15.3, the frameworks (e.g. CCIeNewsNetworking) we build and release seems to reference SwiftUI. Our deployment target is iOS11. Customers have complained when running on iOS12: dyld: Library not loaded: /System/Library/Frameworks/SwiftUI.framework/SwiftUI Referenced from: /private/var/containers/Bundle/Application/81538A25-464A-46E0-BC4D-6E1C002C82F0/Test.app/Frameworks/CCIeNewsNetworking.framework/CCIeNewsNetworking Reason: image not found and I can see that "import SwiftUI" now appears in arm64-apple-ios.private.swiftinterface: diff CCIeNewsNetworking.xcframework-7.3*/ios-arm64/CCIeNewsNetworking.framework/Modules/CCIeNewsNetworking.swiftmodule/arm64-apple-ios.private.swiftinterface 2,4c2,3 < // swift-compiler-version: Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100) < // swift-module-flags: -target arm64-apple-ios11.0 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -Onone -module-name CCIeNewsNetworking < // swift-module-flags-ignorable: -enable-bare-slash-regex --- > // swift-compiler-version: Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4) > // swift-module-flags: -target arm64-apple-ios11.0 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -Onone -enable-bare-slash-regex -module-name CCIeNewsNetworking 7a7 > import DeveloperToolsSupport 9a10 > import SwiftUI 12a14 > import _SwiftConcurrencyShims 217c219 < @objc public func removeOperation(issueIdentifer: Swift.String, fileName: Swift.String) --- > @objc public func removeOperation(issueIdentifier: Swift.String, fileName: Swift.String) I don't recall having changed anything in the project settings, so where does "import SwiftUI" come from, and how can I avoid it ?
Posted Last updated
.
Post not yet marked as solved
2 Replies
214 Views
I am having a problem with named captures when build with a Regex Builder. The following code is a simplistic example of the problem that works using an "ordinary" Regex. but when the same regular regex is created with a Regex Builder, it works when using group numbers, but it raises the following typing problem when using capture names (last lines) Cannot infer type of closure parameter 'm' without a type annotation // named captures and use with a Regex string to twiggle every alternate chars let pat = /(?P<a>.)(?P<b>.)/ "abcdef".replacing(pat,with:{m in "\(m.b)\(m.a)"}) // the same Regex but using a Regex Builder let a = Reference(Substring.self) let b = Reference(Substring.self) let patRB = Regex { Capture(as: a) {.any} Capture(as: b) {.any} } // OK when using capture group numbers "abcdef".replacing(patRB,with:{m in "\(m.2)\(m.1)"}) // compile error when using group names "abcdef".replacing(patRB,with:{m in "\(m.b)\(m.a)"}) The following shows the output strings in a Playground Any hints on what is wrong or on the correct way to add typing information to the closure. Thanks
Posted Last updated
.
Post marked as solved
1 Replies
250 Views
I am trying to create a generic structure in my project and I am facing an issue where I get the error "Type 'any B' cannot conform to 'A'", where protocol B is derived from protocol A. I don't understand why such a structure is problematic and I would really appreciate any insight or alternative solution for this issue I am having. Issue: I have a general base protocol-class pair like the following. protocol A { } class AClass<T: A> { } To give an example of my use case, protocol A can be PresenterLogic where AClass is BaseInteractor. I have a second protocol-class pair which I want to specialize according to its use case. protocol B: A { } class BClass: AClass<B> { } // Here, I get "Type 'any B' cannot conform to 'A'" For example, protocol B being MyPresenterLogic and class BClass being MyInteractor. Specific Use-Case: To give a more specific use case, I am trying to build a VIP structure such as the following. // Base VIP (Ex: Interactor) protocol PresenterLogic { } class Interactor<PL: PresenterLogic>, BusinessLogic { var presenter: PL? } // VIP for Specific Screen (Ex: Interactor) protocol MyPresenterLogic: PresenterLogic { } class MyInteractor: Interactor<MyPresenterLogic> { // I don't want to declare a second `myPresenter: MyPresenterLogic` here } I don't want to declare another presenter instance in MyInteractor, (such as myPresenter: MyPresenterLogic. I want to be able to use the same presenter instance to be inferred to have the sub-protocol type. That is why I want to use generic classes, but I am stuck. I am searching if this is supported. Any insight is appreciated. Thank you.
Posted Last updated
.
Post not yet marked as solved
2 Replies
504 Views
I encountered a compilation issue when trying to use my SDK built in Xcode 15.3 with Xcode 15.2 for our app. According to Apple, Swift provides ABI Stability from Xcode 12.2 onwards, so we didn't face such issues before. Attached is the compilation error message for your reference. SDK is built with 'Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)', while this compiler is 'Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)')
Posted
by MahaSVS.
Last updated
.
Post not yet marked as solved
2 Replies
393 Views
I build an XCFramework in xcode 15.3 and install the framework in my example application. Everything is fine when I run the example app in xcode 15.3, but if I run the example app in xcode 15.2 I get this error: Undefined symbol: _swift_FORCE_LOAD$_swiftXPC Linker command failed with exit code 1 (use -v to see invocation) I made tests with different versions of XCode and differents versions of XCFramework compilation and only versions compiled in XCode 15.3 has problems Resume: App Xcode 15.3 -> Framework 15.3 -> :white_check_mark: App xcode 15.2 -> Framework 15.3 -> :x: App xcode 15.1 -> Framework 15.3 -> :x: App Xcode 15.3 -> Framework 15.2 -> :white_check_mark: App xcode 15.2 -> Framework 15.2 -> :white_check_mark: App xcode 15.1 -> Framework 15.2 -> :white_check_mark: App Xcode 15.3 -> Framework 15.1 -> :white_check_mark: App xcode 15.2 -> Framework 15.1 -> :white_check_mark: App xcode 15.1 -> Framework 15.1 -> :white_check_mark: Could it be a bug on xcode 15.3?
Posted Last updated
.
Post marked as solved
4 Replies
333 Views
I have this code in a network extension: private func pathForToken(token: audit_token_t) -> String? { var tokenCopy = token let bufferSize = UInt32(4096) let bytes = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(bufferSize)) let length = proc_pidpath_audittoken(&tokenCopy, bytes, bufferSize) if length != 0 { return String(cString: bytes).lowercased() } return nil } bytes appears to be leaked -- the call stack is pathForToken(token:) to specialized static UnsafeMutablePointer.allocate(capacity:) Do I need to do something to ensure bytes is released, since it doesn't seem to be happening on its own?
Posted
by kithrup.
Last updated
.